package com.zm.demo.core.concurrent;

import org.junit.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Phaser;
import java.util.concurrent.SynchronousQueue;

import static java.lang.System.out;

/**
 * @author zoum
 * @create 2019/7/1 14:41
 */
public class PhareTest {


    @Test
    public void test() throws InterruptedException{
        Phaser phaser = new Phaser(2);
        ExecutorService pool = Executors.newCachedThreadPool();
        for (int i = 0; i < phaser.getRegisteredParties(); i++) {
            final int j = i;
            pool.submit(() ->{
                out.println("第 "+ j + "到达");
                phaser.arriveAndDeregister();
            });
        }

        phaser.arriveAndAwaitAdvance();
        phaser.awaitAdvance(phaser.getPhase());
        int rValue = phaser.register();

    }
}
